package ae.pcfc.etks.online.itworx.ehs.web.locator.impl;

import ae.pcfc.etks.online.itworx.ehs.web.facade.EHSFacade;
import ae.pcfc.etks.online.itworx.ehs.web.facade.FNPFacade;
import ae.pcfc.etks.online.itworx.ehs.web.facade.Facade;
import ae.pcfc.etks.online.itworx.ehs.web.facade.IMSFacade;
import ae.pcfc.etks.online.itworx.ehs.web.facade.ServiceFacade;
import ae.pcfc.etks.online.itworx.ehs.web.facade.TSCFacade;
import ae.pcfc.etks.online.itworx.ehs.web.facade.WorkflowFacade;
import ae.pcfc.etks.online.itworx.ehs.web.locator.ServiceLocator;

public class ServiceLocatorImpl implements ServiceLocator {

	private WorkflowFacade workflowFacade;
	private FNPFacade fnpFacade;
	private IMSFacade imsFacade;
	private EHSFacade ehsFacade;
	private ServiceFacade serviceFacade;
	private TSCFacade tscFacade;

	public WorkflowFacade getWorkflowFacade() {
		return workflowFacade;
	}

	public void setWorkflowFacade(WorkflowFacade workflowFacade) {
		this.workflowFacade = workflowFacade;
	}

	public FNPFacade getFnpFacade() {
		return fnpFacade;
	}

	public void setFnpFacade(FNPFacade fnpFacade) {
		this.fnpFacade = fnpFacade;
	}

	public IMSFacade getImsFacade() {
		return imsFacade;
	}

	public void setImsFacade(IMSFacade imsFacade) {
		this.imsFacade = imsFacade;
	}

	public EHSFacade getEhsFacade() {
		return ehsFacade;
	}

	public void setEhsFacade(EHSFacade ehsFacade) {
		this.ehsFacade = ehsFacade;
	}
	
	public ServiceFacade getServiceFacade() {
		return serviceFacade;
	}

	public void setServiceFacade(ServiceFacade serviceFacade) {
		this.serviceFacade = serviceFacade;
	}
	
	public TSCFacade getTscFacade() {
		return tscFacade;
	}

	public void setTscFacade(TSCFacade tscFacade) {
		this.tscFacade = tscFacade;
	}

	public <T extends Facade> T getFacadeService(Class<T> type)
			throws RuntimeException {

		if (type != null && workflowFacade != null
				&& type == WorkflowFacade.class) {
			return type.cast(workflowFacade);
		} else if (type != null && fnpFacade != null && type == FNPFacade.class) {
			return type.cast(fnpFacade);
		} else if (type != null && imsFacade != null && type == IMSFacade.class) {
			return type.cast(imsFacade);
		} else if (type != null && ehsFacade != null && type == EHSFacade.class) {
			return type.cast(ehsFacade);
		} else if (type != null && serviceFacade != null && type == ServiceFacade.class) {
			return type.cast(serviceFacade);
		}
		throw new RuntimeException("Unable to find Facade Service for class :"
				+ type.getName());
	}
}
